<?php

namespace Modules\Admin\Services;

use Modules\Admin\Models\Admin;
use \Illuminate\Http\JsonResponse;
use Modules\Common\StatusData;

class AdminService extends BaseService
{

    protected $model = null;
    public function __construct()
    {
        $this->model = new Admin();
    }

    /***
     * @return JsonResponse
     * 管理员列表
     */
    public function list(): JsonResponse
    {
        $list = $this->model->simplePaginate();
        return $this->buildSuccess($list->toArray());
    }

    /***
     * @param array $param
     * @return JsonResponse
     * 添加
     */
    public function store(array $param): JsonResponse
    {

        if ($this->model->create($param)) {
            return $this->buildSuccess();
        }
        return $this->buildFailed(StatusData::ADD_FAILED,'添加失败!');
    }

    /***
     * @param int $id
     * @return JsonResponse
     * 修改信息
     */
    public function edit(int $id): JsonResponse
    {
        $admin = $this->model->where('id',$id)->first()->toArray();
        if ($admin === null){
            return  $this->buildFailed(StatusData::NOT_EXISTS,'用户不存在');
        }
        return $this->buildSuccess($admin);
    }



}
